<template>
    <el-dialog v-model="dialogVisible" title="申请原因" width="500">
        <el-input type="textarea" v-model="reason" placeholder="请输入您遇到的问题" rows="10"></el-input>
        <template #footer>
            <el-button :disabled="formLoading" type="primary" @click="submitForm">提 交</el-button>
            <el-button @click="dialogVisible = false">取 消</el-button>
        </template>
    </el-dialog>
</template>

<script setup>
import { ref } from "vue";
import { service } from "@/config/service";
import { useRouter } from "vue-router";
import { ElMessage } from "element-plus";
const { currentRoute, push, go } = useRouter();
const formLoading = ref(false);
const dialogVisible = ref(false)
const reason = ref('')
/** 打开弹窗 */
const open = async (id) => {
    dialogVisible.value = true;
    resetForm()
};
const resetForm = () => {
    reason.value = ''
}
defineExpose({ open });
const emit = defineEmits(["success"]); // 定义 success 事件，用于操作成功后的回调

/** 提交表单 */
const submitForm = async () => {
    formLoading.value = true
    try {
        await service.get("/member/applyForAfterSales", { params: { orderId: currentRoute.value.query.id, reason: reason.value } });
        ElMessage({
            type: "success",
            message: "提交成功",
        });
        dialogVisible.value = false
        // 发送操作成功的事件
        emit('success')
    } finally {
        formLoading.value = false
    }
}
</script>

<style lang="scss" scoped></style>